import 'package:flutter/material.dart';
import 'package:proj_shop/pages/cart_page.dart';
import 'package:proj_shop/pages/category_page.dart';
import 'package:proj_shop/pages/home_page.dart';
import 'package:proj_shop/pages/member_page.dart';

import 'home_page1.dart';

class IndexPage extends StatefulWidget {
  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  // bottom 数据源
  final List<BottomNavigationBarItem> bottomTabs = [
    BottomNavigationBarItem(
      icon: Icon(Icons.home),
      title: Text("首页"),
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.search),
      title: Text("分类"),
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.shopping_cart),
      title: Text("购物车"),
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.account_circle),
      title: Text("会员中心"),
    ),
  ];

  final List bodyTabs = [
    //HomePage(),
    HomePage1(),
    CateGoryPage(),
    CartPage(),
    MemberPage(),
  ];

  int currentIndex = 0;
  var currentPage;

  @override
  void initState() {
    currentPage = bodyTabs[currentIndex];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color.fromRGBO(244, 245, 245, 1.0),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: currentIndex,
        items: bottomTabs,
        onTap: (int index) {
          setState(() {
            currentIndex = index;
            currentPage = bodyTabs[currentIndex];
          });
        },
      ),
      body: currentPage,
    );
  }
}
